package ai.demo;


import org.springframework.ai.image.Image;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.zhipuai.ZhiPuAiImageModel;
import org.springframework.ai.zhipuai.ZhiPuAiImageOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

@RestController
@RequestMapping("/ai")
public class MyController {


    @Autowired
    private ZhiPuAiImageModel zhiPuAiImageModel;

    @GetMapping("/image")
    public void image() {

        System.out.println("image");

        ImageResponse response = zhiPuAiImageModel.call(
                new ImagePrompt("A light cream colored mini golden doodle",
                        ZhiPuAiImageOptions.builder().withModel("cogview-3").withUser("c726abec52af2452ecaf2534e6f30e14.H7NDtuAOXTbr0ll0").build())

        );

        Image output = response.getResult().getOutput();
        System.out.println(output);

    }
}
